package com.rk.live.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import cn.waps.AppConnect;

import com.rk.live.R;
import com.rk.live.pojo.LoadingPopAd;

public class StartActivity extends Activity {
	private Handler mHandler = new Handler();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
//		View view=View.inflate(this, R.layout.start_activity, null);
//		setContentView(view);
		
		AppConnect.getInstance("84568cc901f653dd3bc8362ee1ad2d74", "waps", this);
        // 使用自定义的OffersWebView
		AppConnect.getInstance(this).setAdViewClassName(this.getPackageName() + ".MyAdView");
        
        // 初始化自定义广告数据
    	AppConnect.getInstance(this).initAdInfo();
    	// 初始化插屏广告数据
    	AppConnect.getInstance(this).initPopAd(this);
    	// 开屏广告
    	View loadingAdView = LoadingPopAd.getInstance().getContentView(this, 3);
    	if(loadingAdView != null){
    		// 将开屏广告的布局View设置到当前Activity的整体布局中
    		this.setContentView(loadingAdView);
    	}
		
		
		Animation animation=AnimationUtils.loadAnimation(this, R.anim.alpha);
		loadingAdView.startAnimation(animation);
		animation.setAnimationListener(new AnimationListener() {
			@Override
			public void onAnimationStart(Animation arg0) {}
			@Override
			public void onAnimationRepeat(Animation arg0) {}
			
			@Override
			public void onAnimationEnd(Animation arg0) {
				mHandler.postDelayed(new Runnable() {
					@Override
					public void run() {
						goHome();
					}
				}, 3000);
			}
		});
	}
	
	private void goHome() {
		this.startActivity(new Intent(this, MainActivity.class));
		AppConnect.getInstance(StartActivity.this).close(); 
		finish();
	};

}
